<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // function getNumberOfBottles(total, exchange) {
      //   let num = 0
      //   // 兑换1次total会减掉exchange瓶，同时这exchange瓶还可以换一瓶
      //   // 相当于兑换一次消耗了exchange-1瓶
      //   while (total >= exchange - 1) {
      //     total = total - (exchange - 1)
      //     num += 1
      //   }
      //   return num
      // }
      // const res = getNumberOfBottles(10, 3)
      // console.log(res)

      let n = +prompt('请输入空瓶子数')
      function getCount(n) {
        if (n <= 1) {
          return 0
        }
        if (n <= 3) {
          return 1
        }
        // 喝到多少瓶水
        const curNum = parseInt(n / 3)
        // 剩余多少瓶子
        const leftNum = n % 3

        return curNum + getCount(curNum + leftNum)
      }
      console.log(getCount(n))
    </script>
  </body>
</html>
